package com.itheima.view;

import com.itheima.data.Customer;
import com.itheima.service.impl.CreditAssessmentSystem;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

/**
 * /*
 * 用户界面
 * 视图层
 */

public class BankReferenceTest {
    private Customer customer;
    public BankReferenceTest() {

    }

    public static void main(String[] args) {
        CreditAssessmentSystem creditAssessmentSystem = new CreditAssessmentSystem();
        Scanner scanner = new Scanner(System.in);

        // 添加客户信息
        List<Customer> list = new ArrayList<>();
        list.add(new Customer(num(list),"王维",18,"男",false,"博士",
                16888.0,0.0, LocalDateTime.of(2019,5,12,12,12,6)));

        list.add(new Customer(num(list),"筱筱",27,"女",true,"本科",
                6888.0,9000, LocalDateTime.of(2008,6,12,12,12,6)));

        list.add(new Customer(num(list),"张强",60,"男",true,"研究生",
                100.0,500.0, LocalDateTime.of(1976,5,12,12,12,6)));

         list.add(new Customer(num(list), "莉莉", 45, "女", false, "本科",
                3000.0, 0.0, LocalDateTime.of(2011, 5, 12, 12, 12, 6)));
        for (Customer customer : list) {
            System.out.println(customer.toString());
        }
        while (true) {
            System.out.println("===银行征信系统===");
            System.out.println("1：查询客户征信");
            System.out.println("2：查询所有客户征信");
            System.out.println("3：退出");
            System.out.println("请录入");
            String type = scanner.next();
            switch (type) {
                case "1":
                    System.out.println("请输入银行账号");
                    String id = scanner.next();
                    //调用业务层----信用评估系统--对输入卡号的客户信息进行判别
                    creditAssessmentSystem.findAssessCreditById(id,list);
                    break;
                case "2":
                    //调用业务层----信用评估系统---对数据库所有客户信息进行判别
                    creditAssessmentSystem.findAssessCredit(list);
                    break;
                case "3":
                    System.out.println("已退出银行信用贷款资格评定系统，欢迎您下次使用！！！！");
                    return;
                default:
                    System.out.println("输入错误");
                    break;
            }
        }

    }

    public static String num( List<Customer> list ) {
        Random random = new Random();
        String id = ""+random.nextInt(9)+1;
        while (true) {
            for (int i = 0; i < 8; i++) {
                int num = random.nextInt(10);
                id += num;
            }
            boolean judge = judge(list, id);
            if (judge==true){

                return id;
            }
        }

    }

    public static boolean judge(List<Customer> list  ,String id){
        if (list.size() != 0){
            for (Customer customer1 : list) {
                if (!customer1.getId().equals(id)) {
                    return true;
                }
            }
        }else {
            return true;
        }


        return false;
    }
}

